<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>社医堂</title>
<link rel="stylesheet" type="text/css" href="./css/api.css" />
<link rel="stylesheet" type="text/css" href="./css/hui.css" />
<link rel="stylesheet" type="text/css" href="./css/iconfont.css" />
</head>
<body>
<header class="hui-header">
	<div id="hui-back"></div>
	<h1>会员注册</h1>
	<div onclick="saoma2()" class="iconfont iconsaoma" id="hui-saoma"></div>
</header>

<div style="height:80px;"></div>

<div class="hui-wrap">

    <div id="cate" style="padding:20px;">
        <div class="hui-segment">
            <a href="javascript:changeDom(1);" class="hui-segment-active">患者注册</a>
            <a href="javascript:changeDom(2);">医生注册</a>
        </div>
    </div>
	
    <div style="margin:20px 10px; margin-bottom:15px;" class="hui-form" id="form1">
        <input type="hidden" id="type" value="0">
        <input type="hidden" id="pcode" value="0">
        <div class="hui-form-items">
        	<div class="hui-form-items-title" id="hzys">医生识别码</div>
            <input id="pcodestr" value="" type="text" readonly class="hui-input hui-input-clear" onclick="saoma2()"  />
        </div>

        <div class="hui-form-items">
        	<div class="hui-form-items-title">用户名</div>
            <input id="mobile" value="" type="text" class="hui-input hui-input-clear" placeholder="如：13900000000" checkType="string" checkData="5,20" checkMsg="用户名应为5-20个字符" />
        </div>
        <div class="hui-form-items">
        	<div class="hui-form-items-title">登录密码</div>
            <input id="password1" value="" type="password" class="hui-input hui-pwd-eye" placeholder="登录密码" checkType="string" id="pwd" checkData="6,20" checkMsg="密码应为6-20个字符" />
        </div>
        <div class="hui-form-items">
        	<div class="hui-form-items-title">确认密码</div>
            <input id="password2" value="" type="password" class="hui-input hui-pwd-eye" placeholder="确认密码" checkType="sameWithId" checkData="pwd" checkMsg="两次密码不一致"  />
        </div>
    </div>    

    <div style="padding:10px; padding-top:10px;">
        <button onclick="rege()" type="button" class="hui-button hui-button-large hui-primary" id="submit" style="width:60%;float:left;">立即注册</button>
		<button onclick="person()" type="button" class="hui-button hui-button-large hui-danger" id="submit" style="width:38%;float:left;margin-left:2%;">登录</button>
    </div>
	
	
	
</div>

<script src="./script/hui.js" type="text/javascript" charset="utf-8"></script>
<script src="./script/hui-swipe.js" type="text/javascript" charset="utf-8"></script>
<script src="./script/api.js" type="text/javascript" charset="utf-8"></script>
<script src="./script/stm.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
apiready = function() {

	var header = $api.dom('header'); // 获取 header 标签元素
    var footer = $api.dom('footer'); // 获取 footer 标签元素
	var headerH = $api.fixStatusBar(header);
	var footerH = $api.fixTabBar(footer);
};


function setval(str){

    //var str = api.pageParam.docid;    
    if(str!='' && str!=null && str!=undefined){
        strArr = str.split("||")
	    document.getElementById("pcodestr").value = strArr[0]
        document.getElementById("pcode").value = strArr[1]
    }

}

function changeDom(index){
    index--;
    hui('#cate a').eq(index).addClass('hui-segment-active').siblings().removeClass('hui-segment-active');
    if(index==0){
        hui("#hzys").html("医生识别码")
        hui("#type").val(0)
    }else{
        hui("#hzys").html("医院识别码")
        hui("#type").val(1)
    }
}




function person(){
    api.openFrame({
        name: 'index',
        url: './index.html',
        bounces: false,
        rect: { // 推荐使用Margin布局，用于适配屏幕的动态变化
            marginTop: 0, // main页面距离win顶部的高度
            marginBottom: 0, // main页面距离win底部的高度
            w: 'auto' // main页面的宽度 自适应屏幕宽度
        }
    });
}

function rege(){

    var pcode     = hui("#pcode").val();
    var mobile    = hui("#mobile").val();
    var password1 = hui("#password1").val();
    var password2 = hui("#password2").val();
    var type      = hui("#type").val();

    if (pcode=='') {
        if(type==0){
            api.toast({ msg:'医生识别码不能为空',location:'top' })
        }else{
            api.toast({ msg:'医院识别码不能为空',location:'top' })
        }
        
        return false;
    }
    if (mobile == '') {
        api.toast({ msg:'用户名不能为空',location:'top' })
        return false;
    }
    if (password1 == '') {
        api.toast({ msg:'密码不能为空',location:'top' })
        return false;
    }
    if (password2 == '') {
        api.toast({ msg:'确认密码不能为空',location:'top' })
        return false;
    }
    if (password1 != password2) {
        api.toast({ msg:'两次密码输入不一致',location:'top' })
        return false;
    }

    api.ajax({
        url: $api.getStorage('geturl')+'&c=ajaxmember&a=register',
        method: 'post',
        data: {
            values: { 
                pcode   : pcode,
                password: password1,
                type    : type,
                mobile  : mobile
            }
        }
    },function(ret, err){
        if (ret) {
            if (ret.status==1) {
                $api.setStorage('userid',ret.data.userid);
                $api.setStorage('docid',ret.data.docid);
                $api.setStorage('hospid',ret.data.hospid);
                $api.setStorage('flag',ret.data.flag);

                api.toast({ msg:ret.tip,location:'top' })
                setInterval("person()",2000)
            }else{
                api.toast({ msg:ret.tip,location:'top' })
            }
        } else {
            alert( JSON.stringify( err ) );
        }
    });   
    
    
}

</script>

</body>
</html>